<?php

     session_start();

    if (!isset($_SESSION['logged'])) {
        @header("Location: login.php");
        die;
    }

    if (!file_exists("../config.php")) {
        @header("Location: ../install.php");
        die;
    }

    require_once("./admin_lib.php");
    
    if (isset($_POST['submit_new_user'])) {
        // TODO: controlli con regexp
        foreach ($_POST as $field) {
            if (is_null($field) || empty($field)) {
                $err=1;
                break;
            }
        }
        if (!isset($err)) {
            unset($_POST['submit_new_user']);
            insert_new_user($_POST);
        }
    }

    include("../global_conf.php");
    include($site->langdir."/languages.php");

    require_once($site->langdir."/".$_SESSION['lang'].".lang.php");

    $usertab="class=\"active\"";
    require_once("./include/sections.php");
    include("./include/admin_header.php");
?>
    <div id="page">
    <div id="page-bgtop">
    <div id="page-bgbtm">
        <div id="content">
    <?php
        if (isset($_GET['a'])) {
            if (strcmp($_SESSION['role'], "all") == 0) {
                switch ($_GET['a']) {
                    case "ins":
                        get_insert_user_section();
                        break;
                    case "lst":
                        get_list_user_section();
                        break;
                }
            }
            else
                echo "<div class=\"error\">".$_LANG['no privileges to list users']."</div>";
        }
        else
            get_user_section();
    ?>
        </div>
        <div style="clear: both">&nbsp;</div>
    </div>
    </div>
    </div>
<?php
    include("./include/admin_footer.php");
?>